package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.AttendanceDetail;
import cn.classyex.business.hr.service.IAttendanceDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考勤详情管理Controller
 * 
 * @author yex
 * @date 2021-05-06
 */
@Controller
@RequestMapping("/hr/attendanceDetail")
public class AttendanceDetailController extends BaseController
{
    private String prefix = "hr/attendanceDetail";

    @Autowired
    private IAttendanceDetailService attendanceDetailService;

    @RequiresPermissions("hr:attendanceDetail:view")
    @GetMapping()
    public String attendanceDetail()
    {
        return prefix + "/attendanceDetail";
    }

    /**
     * 查询考勤详情管理列表
     */
    @RequiresPermissions("hr:attendanceDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AttendanceDetail attendanceDetail)
    {
        startPage();
        List<AttendanceDetail> list = attendanceDetailService.selectAttendanceDetailList(attendanceDetail);
        return getDataTable(list);
    }

    /**
     * 导出考勤详情管理列表
     */
    @RequiresPermissions("hr:attendanceDetail:export")
    @Log(title = "考勤详情管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AttendanceDetail attendanceDetail)
    {
        List<AttendanceDetail> list = attendanceDetailService.selectAttendanceDetailList(attendanceDetail);
        ExcelUtil<AttendanceDetail> util = new ExcelUtil<AttendanceDetail>(AttendanceDetail.class);
        return util.exportExcel(list, "考勤详情管理数据");
    }

    /**
     * 新增考勤详情管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考勤详情管理
     */
    @RequiresPermissions("hr:attendanceDetail:add")
    @Log(title = "考勤详情管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AttendanceDetail attendanceDetail)
    {
        return toAjax(attendanceDetailService.insertAttendanceDetail(attendanceDetail));
    }

    /**
     * 修改考勤详情管理
     */
    @GetMapping("/edit/{attendanceDetailId}")
    public String edit(@PathVariable("attendanceDetailId") Long attendanceDetailId, ModelMap mmap)
    {
        AttendanceDetail attendanceDetail = attendanceDetailService.selectAttendanceDetailById(attendanceDetailId);
        mmap.put("attendanceDetail", attendanceDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存考勤详情管理
     */
    @RequiresPermissions("hr:attendanceDetail:edit")
    @Log(title = "考勤详情管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AttendanceDetail attendanceDetail)
    {
        return toAjax(attendanceDetailService.updateAttendanceDetail(attendanceDetail));
    }

    /**
     * 删除考勤详情管理
     */
    @RequiresPermissions("hr:attendanceDetail:remove")
    @Log(title = "考勤详情管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(attendanceDetailService.deleteAttendanceDetailByIds(ids));
    }
}
